<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js">
    </script>

    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">

    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <link type="text/css" rel="stylesheet" th:href="@{/css/publicartical.css}">
    <link rel="stylesheet"  th:href = "@{/plugins/xcConfirm/xcConfirm.css}">
    <script th:src = "@{/plugins/xcConfirm/xcConfirm.js}"></script>
    <style>
        .mytable{
            font-size: 16px;
            text-align: center;
        }
        .mytable th{
            text-align: center;
        }
    </style>
    <script>
        function getUrlParms(name){
            //获得页面url的某个url参数的方法
            var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if(r!=null)
                return unescape(r[2]);
            return null;
        }
        var id = getUrlParms("rslt");
        // console.log(id);
        if(id=="0"){
            $(function () {
                var txt=  "没有每日一言，请尽快添加";
                // console.log(txt);
                window.wxc.xcConfirm(txt, window.wxc.xcConfirm.typeEnum.error);
            })
        }
        if(id=="2"){
            $(function () {
                var txt=  "删除成功";
                // console.log(txt);
                window.wxc.xcConfirm(txt, window.wxc.xcConfirm.typeEnum.error);
            })
        }
    </script>


</head>
<body>
<nav class="navbar navbar-default">
    <div class="container-fluid">
        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <form class="navbar-form navbar-left" th:action="@{/user/article}" method="post">
                <ul class="nav navbar-nav navbar-form" >
                    <select class="form-control" name="tagid" th:value="${tagid}" >
                        <option value="null" selected disabled hidden th:if="${tagid<0}">请选择</option>
                        <option th:each="tagList:${tagList}"
                                th:selected="${tagList.id eq tagid}"
                            th:text="${tagList.tag}"
                            th:value="${tagList.id}">
                        </option>
                    </select>
                </ul>
                <div class="form-group navbar-form">
                    <input type="text" name="title" class="form-control" placeholder="Search" >
                </div>
                <button type="submit" class="btn btn-default">Submit</button>
            </form>

        </div><!-- /.navbar-collapse -->
    </div><!-- /.container-fluid -->
</nav>
<table class="table  mytable table-bordered">
    <thead>
    <tr>
        <td>发布时间</td>
        <td>文章标题</td>
        <td>封面</td>
        <td>类别</td>
        <td>操作</td>
    </tr>
    </thead>
    <tbody>
    <tr th:each="articleList:${articleList}">
        <td style="line-height: 100px" th:text="${#dates.format(articleList.createtime,'yyyy-MM-dd hh:MM:dd')}">2020-08-18 12:12:12</td>
        <td th:text="${articleList.title}" style="line-height: 100px">前端</td>
        <td >
            <img th:src="${articleList.photo}" alt="" style="width: 100px;height: 100px">
        </td>
        <td th:text="${articleList.tag.tag}" style="line-height: 100px">前端</td>
        <td style="line-height: 100px">
            <a th:href="@{'/admin/updateArticle/'+${articleList.id}}">
                <button class="btn btn-success" >修改</button>
            </a>
            <a id="deleteBtn">
                <button class="btn btn-warning" th:onclick="'deleteArticle('+${articleList.id}+')'">删除</button>
            </a>
        </td>
    </tr>
    </tbody>
</table>
<div class="row">
    <div class="col-md-2">
        <span class="navbar-left">&nbsp;&nbsp;&nbsp;&nbsp;
            共<span th:text="${total}"></span>条
        </span>
    </div>
    <div class="col-md-5"></div>
    <div class="col-md-5">
        <ul class="pagination navbar-right">
            <li><a th:href="@{'/user/article?pageNum='+${currPage-1}}">&laquo;</a></li>
            <li th:each="pageNum:${pages}">
                <a th:href="@{'/user/article?pageNum='+${pageNum}}"th:classappend="${pageNum==currPage}?'active'"th:text="${pageNum}">1</a>
            </li>
            <li><a th:href="@{'/user/article?pageNum='+${currPage+1}}">&raquo;</a></li>
        </ul>
    </div>
</div>


<!--删除-->
<script>
    function deleteArticle(articleid){
        // console.log(tagid)
        var result = confirm("确认删除？")
        if (result){
            //删除
            // var tagid = $("#tagid").attr("value");
            $.ajax({
                url:"[(@{/user/deleteArticle})]",
                data:{"articleid":articleid},
                type:"post",
                success:function (measure) {
                    if (measure == "1"){
                        //删除成功
                        $(function () {
                            var txt = "删除成功";
                            // console.log(txt);
                            window.wxc.xcConfirm(txt, window.wxc.xcConfirm.typeEnum.error);
                        })
                        window.location.href="[(@{/admin/article})]"
                    }
                }
            })
        }
    }
</script>

</body>
</html>